package com.example.goodpet.base;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.goodpet.R;
import com.example.goodpet.common.LoadingPage;

import java.util.Objects;

public abstract  class BaseFragmentForView extends Fragment {
    public LoadingPage loadingPage;
    protected Context mContext;

    private LinearLayout pageError;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        loadingPage=new LoadingPage(requireActivity()) {
            @Override
            public int getLayoutXmlId() {
                return getLayoutId();
            }
        };
        mContext=getContext();
        initView(loadingPage);
        initData();
        LoadPage();
        initTitle();
        initListener();
        return loadingPage;
    }
    public void initListener(){
        pageError.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LoadPage();
            }
        });
    }
    public void initTitle(){}
    /**
     * 加载数据
     */
    protected abstract void LoadPage();

    /**
     * 初始化该页面需要的资源
     */
    protected abstract void initData();

    /**
     * 初始化控件
     */
    protected void initView(View inflate){
        pageError=inflate.findViewById(R.id.page_error);
    }

    /**
     *
     * @return 返回该布局的的layoutId
     */
    public abstract int getLayoutId();
}
